﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace xkcdViewer
{
    public partial class xkcdNum : Form
    {
		public int selectedNum { get; set; }

        public xkcdNum()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            submit();
        }

        private void submit()
        {
            try
            {
                selectedNum = int.Parse(textBox1.Text);
            }
            catch { }
            this.Close();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                int.Parse(textBox1.Text);
            }
            catch
            {
                try
                {
                    String digits = Regex.Replace(textBox1.Text, @"\D", "");
                    textBox1.Text = digits;
                    textBox1.SelectionStart = textBox1.Text.Length;
                }
                catch { }
            }
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                submit();
            }
        }
    }
}
